package com.qs.questionnairesurveysystem.mapper;

import com.qs.questionnairesurveysystem.entity.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    // 插入新问题
    @Insert("INSERT INTO questions (surveyId, content, type, selectContent) VALUES (#{surveyId}, #{content}, #{type}, #{selectContent})")
    void insertQuestion(Question question);

    // 更新问题
    @Update("UPDATE questions SET content = #{content}, type = #{type} WHERE questionId = #{questionId}")
    void updateQuestion(Question question);

    // 删除问题
    @Delete("DELETE FROM questions WHERE questionId = #{questionId}")
    void deleteQuestion(Long questionId);

    // 获取指定问题
    @Select("SELECT * FROM questions WHERE questionId = #{questionId}")
    Question getQuestionById(Long questionId);

    // 获取所有问题
    @Select("SELECT * FROM questions")
    List<Question> getAllQuestions();

    // 根据问卷ID获取问题
    @Select("SELECT * FROM questions WHERE surveyId = #{surveyId}")
    List<Question> getQuestionsBySurveyId(Long surveyId);
}
